package com.atguigu.lease.web.app.controller.history;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.web.app.service.BrowsingHistoryService;
import com.atguigu.lease.web.app.vo.history.HistoryItemVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "浏览历史管理")
@RequestMapping("/app/history")
public class BrowsingHistoryController {

    @Autowired
    private BrowsingHistoryService browsingHistoryService;

    @Operation(summary = "获取浏览历史")
    @GetMapping("pageItem")
    private Result<IPage<HistoryItemVo>> page(@RequestParam long current, @RequestParam long size) {
        Page<HistoryItemVo> page = new Page<>(current, size);

//      todo 同时使用 room_id 来映射属性和给子查询传参时，必须显式(手动)映射 room_id 到 roomId，否则属性值为 null,
//         但子查询正常工作(子查询直接从主查询结果集的列名中取值，与属性映射无关)
//
//      todo 复杂映射冲突：
//         如果 <resultMap> 中存在其他复杂映射(如<collection>)且依赖room_id,
//         <collection>的column="room_id"会从主查询结果集中提取room_id列的值传给子查询
//         MyBatis在处理嵌套查询时,可能将 room_id 标记为"已处理",导致自动映射跳过该列,roomId未被赋值

        IPage<HistoryItemVo> historyItemVoIPage = browsingHistoryService.getHistoryItemVoIPage(page);
        return Result.ok(historyItemVoIPage);
    }

}
